// pages/index/propertyDetailB/propertyDetailB.js
import { API_HOST } from "../../../utils/const"
import http from "../../../utils/http"
import util from "../../../utils/util"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    host: API_HOST,
    bannerData: '',
    cid: '',
    types: '',
    typesTxt: ['', '办公用房', '商业用房', '住宅用房', '工业用房', '其他'],
    officeFacilitys: [],
    facility: [
      {
        'name': '直梯',
        'checked': false,
        'imgUrl': '/assets/img/index/icon/icon_elevator',
        'style': 'width:36rpx; height:36rpx'
      },
      {
        'name': '扶梯',
        'checked': false,
        'imgUrl': '/assets/img/index/icon/icon_escalator',
        'style': 'width:36rpx; height:32rpx'
      },
      {
        'name': '消防梯',
        'checked': false,
        'imgUrl': '/assets/img/index/icon/icon_fire',
        'style': 'width:36rpx; height:36rpx'
      },
      {
        'name': '观光梯',
        'checked': false,
        'imgUrl': '/assets/img/index/icon/icon_sightseeing',
        'style': 'width:32rpx; height:36rpx'
      },
      {
        'name': '品牌电梯',
        'checked': false,
        'imgUrl': '/assets/img/index/icon/icon_brand',
        'style': 'width:36rpx; height:36rpx'
      },
      {
        'name': '中央空调',
        'checked': false,
        'imgUrl': '/assets/img/index/icon/icon_air_conditioning',
        'style': 'width:36rpx; height:36rpx'
      },
      {
        'name': '自动喷淋',
        'checked': false,
        'imgUrl': '/assets/img/index/icon/icon_spray',
        'style': 'width:32rpx; height:36rpx'
      },
      {
        'name': '烟感报警',
        'checked': false,
        'imgUrl': '/assets/img/index/icon/icon_smoke',
        'style': 'width:36rpx; height:36rpx'
      },
      {
        'name': '网络接线',
        'checked': false,
        'imgUrl': '/assets/img/index/icon/icon_interface',
        'style': 'width:36rpx; height:32rpx'
      },
      {
        'name': '智能系统',
        'checked': false,
        'imgUrl': '/assets/img/index/icon/icon_smart',
        'style': 'width:36rpx; height:36rpx'
      },
      {
        'name': '监控系统',
        'checked': false,
        'imgUrl': '/assets/img/index/icon/icon_monitoring',
        'style': 'width:36rpx; height:36rpx'
      },
      {
        'name': '电视天线',
        'checked': false,
        'imgUrl': '/assets/img/index/icon/icon_cable',
        'style': 'width:36rpx; height:36rpx'
      }
      // ,
      // {
      //   'name': '暖气片',
      //   'checked': false,
      //   'imgUrl': '/assets/img/index/icon/icon_heating',
      //   'style': 'width:36rpx; height:36rpx'
      // },
      // {
      //   'name': '其他',
      //   'checked': false,
      //   'imgUrl': '/assets/img/index/icon/icon_other',
      //   'style': 'width:36rpx; height:36rpx'
      // }
    ],
    busFacilitys: [],
    busFacility: [
      {
        'name': '直梯',
        'checked': false,
        'imgUrl': '/assets/img/index/icon/icon_elevator',
        'style': 'width:36rpx; height:36rpx'
      },
      {
        'name': '扶梯',
        'checked': false,
        'imgUrl': '/assets/img/index/icon/icon_escalator',
        'style': 'width:36rpx; height:32rpx'
      },
      {
        'name': '消防梯',
        'checked': false,
        'imgUrl': '/assets/img/index/icon/icon_fire',
        'style': 'width:36rpx; height:36rpx'
      },
      {
        'name': '观光梯',
        'checked': false,
        'imgUrl': '/assets/img/index/icon/icon_sightseeing',
        'style': 'width:32rpx; height:36rpx'
      },
      {
        'name': '品牌电梯',
        'checked': false,
        'imgUrl': '/assets/img/index/icon/icon_brand',
        'style': 'width:36rpx; height:36rpx'
      },
      {
        'name': '中央空调',
        'checked': false,
        'imgUrl': '/assets/img/index/icon/icon_air_conditioning',
        'style': 'width:36rpx; height:36rpx'
      },
      {
        'name': '自动喷淋',
        'checked': false,
        'imgUrl': '/assets/img/index/icon/icon_spray',
        'style': 'width:32rpx; height:36rpx'
      },
      {
        'name': '烟感报警',
        'checked': false,
        'imgUrl': '/assets/img/index/icon/icon_smoke',
        'style': 'width:36rpx; height:36rpx'
      },
      {
        'name': '网络接线',
        'checked': false,
        'imgUrl': '/assets/img/index/icon/icon_interface',
        'style': 'width:36rpx; height:32rpx'
      },
      {
        'name': '智能系统',
        'checked': false,
        'imgUrl': '/assets/img/index/icon/icon_smart',
        'style': 'width:36rpx; height:36rpx'
      },
      {
        'name': '监控系统',
        'checked': false,
        'imgUrl': '/assets/img/index/icon/icon_monitoring',
        'style': 'width:36rpx; height:36rpx'
      },
      {
        'name': '消防栓',
        'checked': false,
        'imgUrl': '/assets/img/index/icon/icon_fire_hydrant',
        'style': 'width:36rpx; height:36rpx'
      },
      {
        'name': '暖气片',
        'checked': false,
        'imgUrl': '/assets/img/index/icon/icon_heating',
        'style': 'width:36rpx; height:36rpx'
      },
      {
        'name': '其他',
        'checked': false,
        'imgUrl': '/assets/img/index/icon/icon_other',
        'style': 'width:36rpx; height:36rpx'
      }
    ],
    imgUrls: [
      'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
    ],
    lat: '',
    lon: '',
    completionDate: '',
    detailInfo: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //console.log('====propertyDetailB options.id:', options.preId,'type:',options.letType);
    this.setData({
      cid: options.preId,
      types: options.letType
    });

    // this.setData({
    //   detailInfo: {
    //     'id': 111,
    //     'title': '自由贸易试验区华京路8号',
    //     'type': '工业用房',
    //     'price': '7000~8000元/日/㎡',
    //     'area1': 500,
    //     'area2': 580,
    //     'wuye': '上海汽车集团股份有限公司',
    //   }
    // });

    this.getInfo(options.preId, options.letType);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onShow: function () {
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  },

  goAround: function(){
    wx.navigateTo({
      url: '/pages/index/map/map?lat='+this.data.lat+'&lon='+this.data.lon
    });
  },

  getInfo: function (cid,types){
    var that = this;
    http({
      url: "/house/queryHouseDetail/v1.0.0",
      data: {//1 => '办公', 2 => '商业', 3 => '住宅', 4 => '厂房'
        'id': cid,
        'type': types
      },
      method: 'POST',
      success: function (res) {
        if (!res) return;
        that.setData({
          detailInfo: res.data,
          lat: res.data.lat,
          lon: res.data.lon
        });
        //console.log('====types:', that.data.officeFacilitys);
        //办公设备设施数据处理
        if (res.data.officeFacilitys){
          that.setData({
            officeFacilitys: res.data.officeFacilitys,
          })
          that.facilityData('bg');
        }
        //商业设备设施数据处理
        if (res.data.busFacilitys) {
          that.setData({
            busFacilitys: res.data.busFacilitys,
          })
          that.facilityData('sy');
        }
        if (res.data.completionDate) {
          let completionDate = util.getYearMonthDay(res.data.completionDate);
          that.setData({
            completionDate: completionDate
          })
        }
      }
    })
  },

  facilityData: function(obj){
    //console.log('obj:',obj);
    let that = this;
    let newList = (obj === 'bg') ? that.data.officeFacilitys : that.data.busFacilitys;
    let originList = (obj === 'bg') ? that.data.facility : that.data.busFacility;
    for (var j = 0; j <= i, j < newList.length; j++) {
      for (var i = 0; i <= originList.length; i++) {
        if (newList[j].key === i) {
          originList[i].name = newList[j].value;
          originList[i].checked = true;
        }
      }
    }
    if (obj === 'bg'){
      that.setData({
        officeFacilitys: originList
      });
    }else{
      that.setData({
        busFacilitys: originList
      });
    }
    

    // var list = this.data.officeFacilitys,
    //   facility = this.data.facility;
    // for (var j = 0; j <= i, j < list.length; j++) {
    //   for (var i = 0; i <= facility.length; i++) {
    //     if (list[j].key === i){
    //       facility[i].name = list[j].value;
    //       facility[i].checked = true;
    //     }
    //   }
    // }
    // this.setData({
    //   officeFacilitys: facility
    // });
    // console.log('==###officeFacilitys:', this.data.officeFacilitys);
  }
})